package com.lamp.date;

import java.io.Serializable;
import java.util.ArrayList;
import java.util.Calendar;
import java.util.Date;
import java.util.List;
import java.util.TimeZone;
import java.util.regex.Matcher;
import java.util.regex.Pattern;

import com.lamp.main.LoginActivity;
import com.lamp.main.R;

import android.content.res.Resources;

public class DateEpoch extends Date implements Serializable {

	/**
	 * 
	 */
	private static final long serialVersionUID = 1L;
	private String epoch;

	public DateEpoch(String epoch) {
		this.setEpoch(epoch);
	}

	public void setEpoch(String epoch) {
		this.epoch = epoch;
	}

	public String getEpoch() {
		return epoch;
	}

	public String showDate() {
		Calendar today = Calendar.getInstance();
		today.setTimeZone(TimeZone.getTimeZone("GMT"));// +0:00"));
		Pattern pattern = Pattern.compile("\\d+");
		Matcher matcher = pattern.matcher(epoch);
		List<String> timeSince = new ArrayList<String>();
		while (matcher.find()) {
			timeSince.add(matcher.group());
		}
		Resources resource = LoginActivity.resource;
		long differenceTime = today.getTimeInMillis() + 3600000
				- Long.parseLong(timeSince.get(0));
		if (differenceTime / 1000 < 60) {
			return Long.toString(differenceTime / 1000) + " "
					+ resource.getString(R.string.sec);

		}
		if (differenceTime / 1000 / 60 < 60) {
			return Long.toString(differenceTime / 1000 / 60) + " "
					+ resource.getString(R.string.min);
		}
		if (differenceTime / 1000 / 60 / 60 < 24) {

			return Long.toString(differenceTime / 1000 / 60 / 60) + " "
					+ resource.getString(R.string.clo);
		}
		if (differenceTime / 1000 / 60 / 60 / 24 < 30) {
			return Long.toString(differenceTime / 1000 / 60 / 60 / 24) + " "
					+ resource.getString(R.string.day);

		}
		if (differenceTime / 1000 / 60 / 60 / 24 / 30 < 12) {
			return Long.toString(differenceTime / 1000 / 60 / 60 / 24 / 30)
					+ " " + resource.getString(R.string.mounth);

		} else
			return Long
					.toString(differenceTime / 1000 / 60 / 60 / 24 / 30 / 12)
					+ " " + resource.getString(R.string.year);

	}
}
